<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.finple.DBConnection"%>
<%@ page import="com.finple.MeetingInfoVo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	request.setCharacterEncoding("UTF-8");

	String initiatorAlias, title, location, password, description, initiatorEmail;

	title = request.getParameter("title");
	location = request.getParameter("location");
	password = "1234";
	description = request.getParameter("description");
	initiatorAlias = request.getParameter("initiatorAlias");
	initiatorEmail = request.getParameter("initiatorEmail");

	try {
		if (title == null || title.equals(""))
			title = "-";
		if (password == null || password.equals(""))
			password = "1234";
		if (location == null || location.equals(""))
			location = "-";
		if (description == null || description.equals(""))
			description = "-";
		if (initiatorAlias == null || initiatorAlias.equals(""))
			initiatorAlias = "-";
		if (initiatorEmail == null || initiatorEmail.equals(""))
			initiatorEmail = "-";
	} catch (Exception e) {
		e.printStackTrace();
	}

	MeetingInfoVo info = new MeetingInfoVo();

	info.setTitle(title);
	info.setPassword(password);
	info.setLocation(location);
	info.setDescription(description);
	info.setInitiatorAlias(initiatorAlias);
	info.setInitiatorEmail(initiatorEmail);
	info.setPollTime("-");
	info.setPollId(16);

	//해당 identifier가 중복되는지 확인하고 중복되면 다른 랜덤 문자열을 입력한다.
	while (DBConnection.GetInst().getMeetingData(info.getPollId()) != null) {
		System.out.println("poll_id가 중복되어 다른 id로 변경");
		info.setPollId(16);
	}

	DBConnection.GetInst().insertMeetingData(info);
%>
</head>
<body>
	<form class="form-container" action="/Finple/data/setting.jsp" method="post">
		<div class="form-contain">
			<table align="center" bgcolor="#FFE65A" width="600px" cellpadding="30">
				<tr>
					<td>
						<div class="process">
							<ol class="inline">
								<li><a href="/Finple/data/create_step1.jsp">Schedule an event</a></li>
								<i class="icon-play icon-white"></i>
								<li><a href="/Finple/data/create_step2.jsp"><span class="text-success">Time proposals</span></a></li>
								<i class="icon-play icon-white"></i>
								<li><a href="/Finple/data/setting.jsp">Settings</a></li>
								<i class="icon-play icon-white"></i>
								<li><a href="/Finple/data/invite.jsp">Invite</a></li>
							</ol>
						</div>
						<div id="header">
							<div id="title">
								<h2 align="center">
									<font color="#8B5927">Time proposals</font>
								</h2>
							</div>
						</div>
						<div>
							입력하신 정보 :<%=info.toString()%>
						</div>
						<div align="center">
							<h5>Click on the date you would like to choose.</h5>
						</div>
						<div>
							<input type="hidden" name="date" id="date" /> <input type="hidden" name="title" value="<%=title%>" /> <input type="hidden" name="location" value="<%=location%>" /> <input type="hidden" name="description" value="<%=description%>" /> <input type="hidden" name="name" value="<%=initiatorAlias%>" /> <input type="hidden" name="email" value="<%=initiatorEmail%>" /> <input type="hidden" name="pollId" value="<%=info.getPollId()%>">
							<div class="submit-container">
								<p class="error otherError" style="display: none;"></p>
								<input type="hidden" name="name" value="3" />
								<button type="button" class="btn btn-success">Back</button>
								<button type="submit" class="btn btn-success" onclick="getdate()">Next step</button>
							</div>
						</div>
					</td>
				</tr>
			</table>
			<%@ page import="com.dhtmlx.planner.*,com.dhtmlx.planner.data.*"%>
			<%!String getPlanner(HttpServletRequest request) throws Exception {
				DHXPlanner s = new DHXPlanner("/Finple/codebase/", DHXSkin.TERRACE);
				s.setWidth(900);
				s.setInitialDate(2013, 5, 12);
				s.load("/Finple/data/events.jsp", DHXDataFormat.JSON);
				s.data.dataprocessor.setURL("/Finple/data/events.jsp");
				return s.render();
			}%>
			<div class="planner" id="planner"><%=getPlanner(request)%></div>
		</div>
	</form>
</body>
</html>